﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Mmht.BT;

public partial class searchPdf : System.Web.UI.Page
{
    public string key = "";
    public int pagesize = 20;
    public int pages = 1;
    public int page = 1;
    public string page_url = "";
    GetPdf gp = new GetPdf();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["type"] == null)
        {
            Response.Redirect("login.aspx");
            return;
        }
        if (!IsPostBack)
        {
            if (Request["key"] == null)
            {
                return;
            }
            key = Request["key"];
            if (Request["page"] != null)
            {
                string p = Request["page"];
                page = int.Parse(p);
            }
            else
            {
                page = 1;
            }
            page = page <= 0 ? 1 : page;
            page_url = Request.Url.ToString().Split('?')[0];
            page_url += "?key=" + key + "&page=[i]";
            controlRepeater1();
        }
    }

    private void controlRepeater1()
    {
        DataTable table1 = gp.SearchPdf(key);
        //借用该字段存储序号
        for (int i = 1; i <= table1.Rows.Count; i++)
        {
            table1.Rows[i - 1]["viewnum"] = i.ToString();
        }
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = table1.DefaultView;
        pds.PageSize = pagesize;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = page - 1;
        int dataTotal = table1.Rows.Count;
        pages = dataTotal % pagesize == 0 ? dataTotal / pagesize : dataTotal / pagesize + 1;
        pages = pages == 0 ? 1 : pages;
        this.Repeater1.DataSource = pds;
        this.Repeater1.DataBind();
    }

}
